package com.kedsoft.docms.service.impl;

import com.kedsoft.docms.entity.Tag;
import com.kedsoft.docms.mapper.TagMapper;
import com.kedsoft.docms.service.TagService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kedsoft.docms.vo.Pagination;
import com.kedsoft.docms.vo.TagSelectVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标签表 服务实现类
 * </p>
 *
 * @author LGP
 * @since 2018-12-03
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    public Pagination<Tag> pageList(Pagination<Tag> pagination, Map<String, Object> query) {
        query.put("offset", pagination.offset());
        query.put("limit", pagination.limit());
        query.put("sort", pagination.getSort());
        query.put("order", pagination.getOrder());
        pagination.setItems(baseMapper.list(query));
        pagination.setTotal(baseMapper.count(query));
        return pagination;
    }

    @Override
    public List<TagSelectVo> getAll() {
        List<Tag> list = baseMapper.listAll();
        List<TagSelectVo> result = new ArrayList<>();
        TagSelectVo top = new TagSelectVo();
        top.setId(0);
        top.setText("--标签--");
        result.add(top);
        if(list == null)
            return result;
        else{
            for(Tag tag : list){
                TagSelectVo selectVo = new TagSelectVo();
                selectVo.setId(tag.getId());
                selectVo.setText(tag.getTagname());
                result.add(selectVo);
            }
        }
        return result;
    }
}
